The Elder Scrolls Forums

TES Construction Set and Plugins >> General TES Construction Set

Pages: 1 | 2 | (show all)
Limorkil
Adept

Reged: 08/28/02
Posts: 388
Loc: Atlanta, Georgia, USA
Best practice for using RemoveItem?
      #2916968 - 08/11/04 04:19 PM

I've been scripting a lot recently and I've come to the following conclusion, which may or may not be a true statement:

"When doing a local script on an object, always call a global or a targetted script to deal with any RemoveItem statements."

This may be total BS, but it works for me. Whenever I use RemoveItem in a local script I always get CTDs in game, or doubling or something going wrong.

Now I know you cannot use RemoveItem on an object in the local script of that object: an item cannot remove itself. But I get CTDs and stuff using RemoveItem on any object from a local script, whether the object has its own local script or not. However, if I call a global or a targetted script I never get any problems.

The format of the local script would be something like this:

Begin local_script

. . .

If ( whatever )
Player->StartScript "RemoveStuff"
Endif

. . .

End

Where "Player" could just as easily be an NPC or other object, depending on the purpose of the script.

And the targetted script would look like this:

Begin RemoveStuff

StopScript, "RemoveStuff"

If ( GetItemCount, "Object_needs_to_go" > 0 )
RemoveItem, "Object_needs_to_go", 1
Endif

End

-----------
The targetted script could be more complicated if there are multiple items and conditions.

This does not work if your local script needs for the item to have gone before doing something else, since the targetted script won't run until the local script finishes its current pass through. You can easily count frames to get round this, if necessary.

I don't think of this as a rule or anything, just something I observed. I'd be interested to know what other people think. I suspect the problems with RemoveItem and other script functions are a result of having too many things going on at once, seeing as the more mods I install the more problems I seem to get. Of course, having a slower PC doesn't help. When the frame rate is low-ish the animation for equipping items, drawing weapons and other inventory changes seems to run slower than the scripts and it almost looks as though the scripts get ahead of functions like RemoveItem, AddItem, Equip etc., which causes failures.


--------------------
Zorremalku the Dunmer Phantom Elite (Xbox)
Level: 18
High Skills: Short Blade (80) Mysticism (71) Destruction (64)
Factions: Temple(8), Telvanni(6), Mages(8), Morag Tong(7)
Current loc/activity: Stuck in Sadrith Mora for the moment while Limorkil's obsession with Leifang runs its course
Updated: 8/9/04

Post Extras: Print Post   Remind Me!   Notify Moderator  
JOG
Curate

Reged: 09/15/02
Posts: 745
Re: Best practice for using RemoveItem? [Re: Limorkil]
      #2917001 - 08/11/04 04:29 PM

Well, this is very old news (a bit more than 2 years )

When you have more than one of those items in your inventory then nothing will happen, but when the last of those items is removed, the script suddenly will loose it's root-object and MW will crash.

Any other script can remove this item, no matter if it's a global or another local script (for example when you exchange two weapons for different weapon-styles like Katane one and two handed)


--------------------
Havish (Updated to v1.2 !!!)

Pirates! (WIP)

My Morrowind Corner

Post Extras: Print Post   Remind Me!   Notify Moderator  
SiNNeR
Disciple

Reged: 09/30/02
Posts: 1909
Loc: a padded cell
Re: Best practice for using RemoveItem? [Re: Limorkil]
      #2917002 - 08/11/04 04:29 PM

Quote:

Now I know you cannot use RemoveItem on an object in the local script of that object: an item cannot remove itself





in which case you may have inadvertantly answered a question I just asked in my own thread, lol. I tried making a ring that'd teleport the PC and remove itself from the inventory afterwards. I assumed it was the teleport that was crashing the game

--------------------

Playable Dremora Project (tmp site)

temp home of my plugins

Cthulhu's coming to Morrowind......

Post Extras: Print Post   Remind Me!   Notify Moderator  
slategrey
Curate

Reged: 06/25/02
Posts: 494
Loc: Finland
Re: Best practice for using RemoveItem? [Re: SiNNeR]
      #2917066 - 08/11/04 04:49 PM

Yep you are right Limorkil, Morrowind really hates items that try to remove themselves from inventory, like it hates objects in your inventory casting spells at the player.

My preferred method, which is probably nowhere near the best method but works well for me. Is the object that needs to remove itself from your inventory creates a ring at the feet of the player for 1 frame. The ring removes the object from your inventory then disables itself and setdelete 1's itself.

If anyones got a better method, I'm all eyes. Normally I'd say all ears, but well.......you understand don't you

-----------------------------------------

--------------------
---------------------------------------------
Founder and "Soul" member of the "I love Kai Globes" Fan Club

Kai Globes v2.8, Apprentice Scrolls and Mystic Quills v1.4 . Don't leave Home without them.

Multi Manniquins V1.2; The Manniquin that changes to suit your needs.


Post Extras: Print Post   Remind Me!   Notify Moderator  
SiNNeR
Disciple

Reged: 09/30/02
Posts: 1909
Loc: a padded cell
Re: Best practice for using RemoveItem? [Re: slategrey]
      #2917085 - 08/11/04 04:54 PM

let's call the script you place on the item script1. how about if script1 did all it was supposed to and also activated script2 a completely unconected script whose only purpose was to remove the item. would that work?

--------------------

Playable Dremora Project (tmp site)

temp home of my plugins

Cthulhu's coming to Morrowind......

Post Extras: Print Post   Remind Me!   Notify Moderator  
slategrey
Curate

Reged: 06/25/02
Posts: 494
Loc: Finland
Re: Best practice for using RemoveItem? [Re: SiNNeR]
      #2917107 - 08/11/04 05:01 PM

I tried that and couldnt get it to work. You can't start and stop local scripts like you can global scripts (thats what ghans guide says.). plus if the second script is called by object to be deleted, that script is on the object now, you've still got the same problem of the item trying to delete itself.

The whole thing was giving me a headache, so I use the second script on another object to delete the first object.

If anyone can stop a script on a local object and then start a second script on that object, I'd REALL be interested. I failed miserably


--------------------
---------------------------------------------
Founder and "Soul" member of the "I love Kai Globes" Fan Club

Kai Globes v2.8, Apprentice Scrolls and Mystic Quills v1.4 . Don't leave Home without them.

Multi Manniquins V1.2; The Manniquin that changes to suit your needs.


Post Extras: Print Post   Remind Me!   Notify Moderator  
Archived User Account

Re: Best practice for using RemoveItem? [Re: Limorkil]
      #2917430 - 08/11/04 06:30 PM

I must have used RemoveItem in about 50 scripts, and I dont think I've ever had a problem with it. I've never tried a script on an item removeing itself, but remote scripts have always, always worked.

If ( Player->GetitemCount "ID" > 0 )
Player->RemoveItem "ID" 1
endif

in fact I've used exactly this format to remove up to 2 million items from the players inventory (Gold_001) without a single CTD or error of any kind.

I have always used it on objects in the cell...doors, NPCs, containers that kind of thing, never on the object itslef.

Post Extras: Print Post   Remind Me!   Notify Moderator  
Wizthis
Adept

Reged: 05/31/04
Posts: 264
Loc: In front of my computer at the moment
Re: Best practice for using RemoveItem? [Re: ]
      #2917733 - 08/11/04 07:53 PM

I tryed this with scripts...and the K.I.S.S. principal applies most of the time for repeat events. Dioulogue works 4 me.

GetItemCount avaros_guard_helm = 1
RemoveItem avaros_guard_helm 1
Player->AddItem, "avaros_guard_helm" 1

The only reason I stuck my nose into this was to see if I'm missing something-and to learn if I am. Maybe a script is better and I do need to learn more. Thanks guys.

--------------------
Here are Links to .DDS, .Tga, .Nif, 3D Programs and Plug-ins.

Post Extras: Print Post   Remind Me!   Notify Moderator  
Wierd
Adept

Reged: 04/03/03
Posts: 342
Re: Best practice for using RemoveItem? [Re: Wizthis]
      #2918038 - 08/11/04 09:08 PM

GetItemCount WhateverItemItIS = 1

will return false if there is more than one of the item. A better one would be

GetItemCount WhateverItemItIs > 0

Because that would return true so long as there is at least one of them.

Post Extras: Print Post   Remind Me!   Notify Moderator  
Wizthis
Adept

Reged: 05/31/04
Posts: 264
Loc: In front of my computer at the moment
Re: Best practice for using RemoveItem? [Re: Wierd]
      #2918636 - 08/11/04 11:52 PM

Quote:

GetItemCount WhateverItemItIS = 1
will return false if there is more than one of the item. A better one would be
GetItemCount WhateverItemItIs > 0
Because that would return true so long as there is at least one of them.




I knew stikin my snoz into this would pan out.
I did have one problem-you sir may have solved it. Thank You!
One thing-Do I write:
GetItemCount WhateverItemItIs > 0
or
GetItemCount WhateverItemItIs >= 0
Thanks again.

--------------------
Here are Links to .DDS, .Tga, .Nif, 3D Programs and Plug-ins.

Post Extras: Print Post   Remind Me!   Notify Moderator  
Wierd
Adept

Reged: 04/03/03
Posts: 342
Re: Best practice for using RemoveItem? [Re: Wizthis]
      #2918709 - 08/12/04 12:12 AM

The first one:

GetItemCount WhateverItemItIs > 0

This is because the second one is saying "Greater than or equal to 0", which would *ALWAYS* return true, since you cannot have negative inventory. Gotta watch out for those logical operators.

If you wanted to use >=, then you should evaluate against 1, and not 0, like this:

GetItemCount WateverItemItIs >= 1

Since that returns true if "one or more" exist. I personally perfer the "More than 0", since the count is of whole numbers. I'd use the "1 or more" if I was using FLOATs, instead of SHORTs, since they involve a decimal point.

Post Extras: Print Post   Remind Me!   Notify Moderator  
Wizthis
Adept

Reged: 05/31/04
Posts: 264
Loc: In front of my computer at the moment
Re: Best practice for using RemoveItem? [Re: Wierd]
      #2918751 - 08/12/04 12:22 AM

GetItemCount Wierds_Hat > 0 ;Takes Wierds Cool hat cause I like it!

Thank you Wierd for showing me this, it is very much appreciated.
(And I want that Hat!)


--------------------
Here are Links to .DDS, .Tga, .Nif, 3D Programs and Plug-ins.

Post Extras: Print Post   Remind Me!   Notify Moderator  
Wierd
Adept

Reged: 04/03/03
Posts: 342
Re: Best practice for using RemoveItem? [Re: Wizthis]
      #2918768 - 08/12/04 12:27 AM

lol-- It's not my hat, it belongs to my brother. I normally dont wear hats because they drive me nuts.

He put that hat on my head, and took the picture. That look of 'displeasure' is a genuine expression, caught on film. LOL It just struck me as being very "van helsing"/"Vampire hunter D"-ish, considering my face, and the long hair, so I used it as my avatar.

Post Extras: Print Post   Remind Me!   Notify Moderator  
qarl
Disciple

Reged: 05/07/02
Posts: 1111
Loc: Michigan
Re: Best practice for using RemoveItem? [Re: ]
      #2918831 - 08/12/04 12:52 AM

Quote:

I must have used RemoveItem in about 50 scripts, and I dont think I've ever had a problem with it. I've never tried a script on an item removeing itself, but remote scripts have always, always worked.





I concure.

--------------------
-qarl
@}-----;----
My mods
WIP: The Underground
Tutorials

Post Extras: Print Post   Remind Me!   Notify Moderator  
Limorkil
Adept

Reged: 08/28/02
Posts: 388
Loc: Atlanta, Georgia, USA
Re: Best practice for using RemoveItem? [Re: JOG]
      #2920263 - 08/12/04 12:11 PM

Quote:

Well, this is very old news (a bit more than 2 years )




Interesting, because I've never seen anyone say the same thing. We all know about local scripts trying to remove themselves, but not that using RemoveItem in any local script on any item seems to be high risk. In fact, comments by other people on this same thread suggest that they have never had a problem with RemoveItem as long as it is not targetting the object with a script, in which case this "old" information has survived a long time in error these people correcting it.

Quote:

in which case you may have inadvertantly answered a question I just asked in my own thread, lol. I tried making a ring that'd teleport the PC and remove itself from the inventory afterwards. I assumed it was the teleport that was crashing the game




Yeah thats kind of "Rule 0" for RemoveItem.

Quote:

Yep you are right Limorkil, Morrowind really hates items that try to remove themselves from inventory




For me at least, Morrowind hates using RemoveItem on any object in any local script.

Quote:

My preferred method, which is probably nowhere near the best method but works well for me. Is the object that needs to remove itself from your inventory creates a ring at the feet of the player for 1 frame. The ring removes the object from your inventory then disables itself and setdelete 1's itself.




A targetted or global script is pretty much the same idea, except there is no object involved. You see if I did exactly what you do then I would get a CTD, since RemoveItem in a local script has that tendancy for me. It's not like it happens 100%, but my chance of CTDs seems to go way up.

Quote:

let's call the script you place on the item script1. how about if script1 did all it was supposed to and also activated script2 a completely unconected script whose only purpose was to remove the item. would that work?




That is exactly what I was suggesting as a 'safe' method of using RemoveItem. It's covered in Morrowind Scripting For Dummies, but its given as a solution to a specific issue as opposed to a best practice.

Quote:

I tried that and couldnt get it to work. You can't start and stop local scripts like you can global scripts (thats what ghans guide says.). plus if the second script is called by object to be deleted, that script is on the object now, you've still got the same problem of the item trying to delete itself.

The whole thing was giving me a headache, so I use the second script on another object to delete the first object.

If anyone can stop a script on a local object and then start a second script on that object, I'd REALL be interested. I failed miserably




The object has the local script, and that script is not stopped. What happens is that the local script starts a second script that is not attached to any object ( a global script ) or a script that is targetted on some object other than the object to be removed ( I always use the Player as the object, e.g. Player->Startscript. "a global script". It works amazingly well, for me at least.

Quote:

I must have used RemoveItem in about 50 scripts, and I dont think I've ever had a problem with it. I've never tried a script on an item removeing itself, but remote scripts have always, always worked.




Remote scripts work for me too, as long as they are not on inventory items.

Quote:

I have always used it on objects in the cell...doors, NPCs, containers that kind of thing, never on the object itslef.




I suppose thats the difference. Most of the scripts I am doing are on moveable objects, inventory items - i.e. stuff that moves around with the player.

Quote:

I concure.




Unfortunately, my experience is the exact opposite. I've done lots of scripts and when testing them I always get a few CTD type errors when RemoveItem is involved. Even if I don't get a CTD every time, it seems as though the scripts are more unstable. As I said in my original post, it must be because I have too many mods running too many scripts, or a crappy PC.

It IS good to know that other people don't have the same problems I have. That means the problem is with my configuration or scripting.


--------------------
Zorremalku the Dunmer Phantom Elite (Xbox)
Level: 18
High Skills: Short Blade (80) Mysticism (71) Destruction (64)
Factions: Temple(8), Telvanni(6), Mages(8), Morag Tong(7)
Current loc/activity: Stuck in Sadrith Mora for the moment while Limorkil's obsession with Leifang runs its course
Updated: 8/9/04

Post Extras: Print Post   Remind Me!   Notify Moderator  
JOG
Curate

Reged: 09/15/02
Posts: 745
Re: Best practice for using RemoveItem? [Re: Limorkil]
      #2920432 - 08/12/04 01:04 PM

Quote:

Interesting, because I've never seen anyone say the same thing. We all know about local scripts trying to remove themselves, but not that using RemoveItem in any local script on any item seems to be high risk.




What do you mean with a "script trying to remove itself"?

You can't remove an item from it's own script, that's a fact. This was common knowledge when I made "Newtscale Hardening" over two years ago. It's used in ever parrying-bracer mod that creates a dummy-shield, every weapon-style switch mod, and every mod that adds usable misc items (like potions, Ioun stones etc.) since the dawn of time.

Simply start a global script that removes the item. No targeting needed. This info was in the very first issue of "Scripting for Dummies".


You can use removeitem in local scripts of course, you're just not allowed to remove the object the script is running off. (or better: you're not allowed to remove all of those objects, it's okay to remove one when the player has two.)


--------------------
Havish (Updated to v1.2 !!!)

Pirates! (WIP)

My Morrowind Corner

Post Extras: Print Post   Remind Me!   Notify Moderator  
ManaUser
Master

Reged: 05/31/00
Posts: 6115
Loc: Long Beach, CA, USA
Re: Best practice for using RemoveItem? [Re: Limorkil]
      #2920641 - 08/12/04 02:26 PM

There was a topic a while back (but not two years, more liek two months) about this and I wish I could remember exactly what we figured out in it. I do remember that equipable scripted items in particular caused problems, and that Drop caused less problems than RemoveItem.

Post Extras: Print Post   Remind Me!   Notify Moderator  
Limorkil
Adept

Reged: 08/28/02
Posts: 388
Loc: Atlanta, Georgia, USA
Re: Best practice for using RemoveItem? [Re: JOG]
      #2920865 - 08/12/04 03:20 PM

Quote:


You can't remove an item from it's own script, that's a fact. This was common knowledge when I made "Newtscale Hardening" over two years ago. It's used in ever parrying-bracer mod that creates a dummy-shield, every weapon-style switch mod, and every mod that adds usable misc items (like potions, Ioun stones etc.) since the dawn of time.




Most people know that. I even mentioned in my original post that we know that. It's pretty much Rule 0 for local scripting. But that's not what my post is about. I guess I didn't explain it well enough. All I'm saying is that RemoveItem is unreliable in local scripts on inventory items, even when its not used on the item that the script is attached to. I was merely trying to find out whether RemoveItem was as unreliable for everyone else as it was for me. Sorry for the confusion.

--------------------
Zorremalku the Dunmer Phantom Elite (Xbox)
Level: 18
High Skills: Short Blade (80) Mysticism (71) Destruction (64)
Factions: Temple(8), Telvanni(6), Mages(8), Morag Tong(7)
Current loc/activity: Stuck in Sadrith Mora for the moment while Limorkil's obsession with Leifang runs its course
Updated: 8/9/04

Post Extras: Print Post   Remind Me!   Notify Moderator  
highpressure
Curate

Reged: 09/16/02
Posts: 870
Loc: Traversing the Spiritual Plane seeking the wisdom of the Higher Power.
Re: Best practice for using RemoveItem? [Re: Limorkil]
      #2921482 - 08/12/04 06:17 PM

O.K. could someone please give me an example of a global script that will remove let's say, a helm my PC is wearing and place it in his inventory.

I really need help with this!

--------------------
Highpressure's Morrowind
Honoring Mods & Mod-Makers




Post Extras: Print Post   Remind Me!   Notify Moderator  
ManaUser
Master

Reged: 05/31/00
Posts: 6115
Loc: Long Beach, CA, USA
Re: Best practice for using RemoveItem? [Re: highpressure]
      #2921718 - 08/12/04 07:15 PM

Quote:

O.K. could someone please give me an example of a global script that will remove let's say, a helm my PC is wearing and place it in his inventory.

I really need help with this!



Okay, that's not quite the same, but the best way to do that (if you have one of the expansions) is like this:

Player->AddItem FakeHelm, 1
Player->Equip FakeHelm
Player->RemoveItem FakeHelm, 1

Where FakeHelm is a dummy item (type helm) you've created for this purpose.

Post Extras: Print Post   Remind Me!   Notify Moderator  
highpressure
Curate

Reged: 09/16/02
Posts: 870
Loc: Traversing the Spiritual Plane seeking the wisdom of the Higher Power.
Re: Best practice for using RemoveItem? [Re: ManaUser]
      #2921744 - 08/12/04 07:21 PM

Thanks a bunch ManaUser!

But what if I have a script attached to the Helm. That last 8 hours but then I want it to be removed from the PC and place in the inventory? By the way I have both expansions.

--------------------
Highpressure's Morrowind
Honoring Mods & Mod-Makers




Post Extras: Print Post   Remind Me!   Notify Moderator  
ManaUser
Master

Reged: 05/31/00
Posts: 6115
Loc: Long Beach, CA, USA
Re: Best practice for using RemoveItem? [Re: highpressure]
      #2922141 - 08/12/04 09:16 PM

That shouldn't be a problem. The trouble is with taking away a scripted item (destroying in other words), not just un-equiping it.

Post Extras: Print Post   Remind Me!   Notify Moderator  
JOG
Curate

Reged: 09/15/02
Posts: 745
Re: Best practice for using RemoveItem? [Re: Limorkil]
      #2931906 - 08/15/04 10:16 AM

Quote:

All I'm saying is that RemoveItem is unreliable in local scripts on inventory items, even when its not used on the item that the script is attached to. I was merely trying to find out whether RemoveItem was as unreliable for everyone else as it was for me.




Its just for you. Countless mods remove items from local script. See my 2 year old "Newtscale Hardening" (Recipe removes ingredients) See any Parrying Bracer mod (Dummy shield is removed by bracer's script when you unequip it) See any Fighting-Style Mod (Two Handed Katana removes One Handed Katana when you switched styles)

Absolutely no problems with such scripts in the last two years.

--------------------
Havish (Updated to v1.2 !!!)

Pirates! (WIP)

My Morrowind Corner

Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1 | 2 | (show all)


Extra information
1 registered and 3 anonymous users are browsing this forum.

Moderator:  Umrahel, Freddo, Pete, Hungry Donner, Attrebus, Miltiades, tegger 

Print Thread

Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Thread views: 163

Rate this thread
 
Jump to

The Elder Scrolls Homepage

*
UBB.threads™ 6.3

Click for Privacy Statement © 2003 Bethesda Softworks LLC, a ZeniMax Media company. All Rights Reserved.
PRIVACY POLICY | TERMS & CONDITIONS | LEGAL INFORMATION | CONTACT US